package com.nf.health.app.mine.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.utils.PreferenceHelper;
import com.nf.health.app.utils.ViewUtil;

/** 
* @ClassName: ModifyPwActivity 
* @Description:修改密码页面
* @author Ian 
* @date 2015-11-4 上午9:56:38 
*  
*/
public class ModifyPwActivity extends BaseActivity implements OnClickListener {
	private EditText current_pwd, pws_one, pws_two;
	private Button bt_success_submit;
    @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setTitleBar(R.layout.titlebar_base);
		setContent(R.layout.activity_account_pw);
		ViewUtil.setText(this, R.id.titlebar_title_tv, "修改密码");
		
		current_pwd = (EditText) findViewById(R.id.current_pwd);
		pws_one = (EditText) findViewById(R.id.pws_one);
		pws_two = (EditText) findViewById(R.id.pws_two);
		bt_success_submit = (Button) findViewById(R.id.bt_success);
		
		bt_success_submit.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_success:
			String cruPsw = current_pwd.getText().toString();
			String pwsone = pws_one.getText().toString();
			String pwstwo = pws_two.getText().toString();
			if ((!TextUtils.isEmpty(cruPsw)) && (!TextUtils.isEmpty(pwsone))
					&& (!TextUtils.isEmpty(pwstwo))) {
				if(pwsone.length()<6){
					showToast("密码必须大于6位");
					return;
				}
				
				if (pwsone.equals(pwstwo)) {
					provider.requestChangePassword(pwsone, cruPsw, "changePassword");
				} else {
					showToast(R.string.pwd_inconsistency);
				}
			} else {
				showToast(R.string.pwd_not_blank);
			}
			break;
		}
		super.onClick(v);
	}

	@Override
	public void handleActionSuccess(String actionName, Object object) {
		super.handleActionSuccess(actionName, object);
		if (actionName.equals("changePassword")) {
			showToast("修改密码成功！");
			PreferenceHelper.putString(PreferenceHelper.PASSWORD, pws_two.getText().toString());
			this.finish();
		}
	}

}
